//
//  UIBarButtonItem+Extensions.swift
//  LJWeibo
//
//  Created by 连俊杨 on 2017/10/7.
//  Copyright © 2017年 yang_ljun. All rights reserved.
//

import Foundation

extension UIBarButtonItem {
    
    /// 便利构造函数创建自定义高亮导航按钮
    ///
    /// - Parameters:
    ///   - title: title description
    ///   - fontSize: fontSize description
    ///   - target: target description
    ///   - action: action description
    convenience init(title: String, fontSize: CGFloat = 16, target: Any?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        
        /// 便利构造函数需要调用自身的构造函数创建自己
        self.init(customView: btn)
    }
}

